package server.business.shop.handler;

import com.core.initialize.Message;
import com.google.protobuf.GeneratedMessage;

import server.ServerConfigCache;
import server.ServerHandler;
import server.ServerTransportProxy;
import server.business.shop.config.ShopConfig;
import server.commonData.User;
import server.messageId.S2CMessageId;
import server.msgBean.ShopMessage.ShopItem;
import server.msgBean.ShopMessage.ShopItemListRes;

/**
 * 请求获得商城道具集合
 * @author King
 *
 */
public class ShopListHandler extends ServerHandler {

	@Override
	public Class<? extends GeneratedMessage> initBodyClass() {
		return null;
	}

	@Override
	protected void handler(Message msg, User user) throws Throwable
	{
		msg.clearDate();
		msg.setModuleAction(S2CMessageId.Shop.MODULE_ID,S2CMessageId.Shop.SHOP_LIST_RES);
		ShopItemListRes.Builder builder = ShopItemListRes.newBuilder();
		for(ShopConfig conifConfig:ServerConfigCache.shopMap.values())
		{
			ShopItem.Builder shopBuilder = ShopItem.newBuilder();
			shopBuilder.setIconId(conifConfig.iconId);
			shopBuilder.setItemId(conifConfig.itemId);
			shopBuilder.setNeedYuanbao(conifConfig.needYuanbao);
			builder.addItems(shopBuilder);
		}
		msg.setBody(builder);
		ServerTransportProxy.sendMsg(msg, user);
	}

}
